package net.turkishpt;

import java.util.ArrayList;

import net.zemberek.erisim.Zemberek;
import net.zemberek.tr.yapi.TurkiyeTurkcesi;

public class DictionaryValidator {
	
	static final Zemberek zemberek = new Zemberek(new TurkiyeTurkcesi());
	
	/**
	 * Validates word whether it is appopriate for Turkish
	 * grammar and exists in dictionary. It replaces all characters
	 * with uppercase ones because of misspelling cases of proper 
	 * nouns.
	 * 
	 * @param word
	 * @return <code>true</code> if valid, <code>false</code>
	 * otherwise.
	 */
	public static boolean validate(String word){
		return zemberek.kelimeDenetle(word.toUpperCase(LetterSequenceFilter.TURKISH));
	}
	
	public static ArrayList<String> validateAll(ArrayList<String> words){
		ArrayList<String> validated = new ArrayList<String>();
		
		for(String word: words)
			if(validate(word))
				validated.add(word);
		
		return validated;
	}
}
